//package org.jackkang.elasticsearch.configuration;
//
//import java.io.IOException;
//
//import org.elasticsearch.client.Client;
//import org.elasticsearch.client.transport.TransportClient;
//import org.elasticsearch.common.settings.ImmutableSettings;
//import org.elasticsearch.common.settings.Settings;
//import org.elasticsearch.common.transport.InetSocketTransportAddress;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
//import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
//import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
//
//@Configuration
//@EnableElasticsearchRepositories(basePackages = "org.jackkang.elasticsearch.repository,org.jackkang.elasticsearch.controller,org.jackkang.elasticsearch.util")
//public class ElasticsearchConfig {
//	@Bean
//	ElasticsearchOperations elasticsearchTemplate() throws IOException {
//		// transport client
//		Settings settings = ImmutableSettings.settingsBuilder()
//		        .put("cluster.name", "elasticsearch")
//		        //5个主分片
//	             .put("number_of_shards", 5)
//	             //测试环境，减少副本提高速度
//	            .put("number_of_replicas", 0).build();
//		        /*.put("username","myname")
//		        .put("password","mypassword").build();*/
//		        
//		 Client client = new TransportClient(settings)
//	        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
//		 
//			/*//首先创建索引库
//			CreateIndexResponse  indexresponse = client.admin().indices()
//			//这个索引库的名称还必须不包含大写字母
//			//.prepareCreate("news").setSettings(settings)
//			.prepareCreate("news_database").setSettings(settings)
//			.execute().actionGet();*/
//		 
//		 return new ElasticsearchTemplate(client);
//		// node client
//		//		return new ElasticsearchTemplate(nodeBuilder()
//		//				.local(true)
//		//				.settings(
//		//						ImmutableSettings.settingsBuilder()
//		//								.put("cluster.name", "elasticsearch")
//		//								.put("username", "myname")
//		//								.put("password", "mypassword").build()).node()
//		//				.client());
//	}
//}